package zhuyun.code


fun main(args:Array<String>){
    val yellow = Yellow()
    val red = Red()
    val handBag1 = HandBag()
    val handBag2 = HandBag()
    val wallet1 = Wallet()
    val wallet2 = Wallet()
    handBag1.color = yellow
    handBag2.color = red
    wallet1.color = yellow
    wallet2.color = red
    println(handBag1.getName())
    println(handBag2.getName())
    println(wallet1.getName())
    println(wallet2.getName())
}

interface Color{
    fun getColor():String
}
class Yellow:Color{
    override fun getColor(): String {
        return "黄色"
    }
}
class Red:Color{
    override fun getColor(): String {
        return "红色"
    }
}
abstract class Bag{
    lateinit var color:Color
    abstract fun getName():String
}
class HandBag:Bag(){
    override fun getName(): String {
        return "${color.getColor()}挎包"
    }
}
class Wallet:Bag(){
    override fun getName(): String {
        return "${color.getColor()}钱包"
    }

}

